<?php
$user = $data['user'];
//dump($data);
?>
<!DOCTYPE html>
<html lang="zhcn">
<head>
    <include file="Common/meta" />
    <title>个人信息修改 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
    <style>
        .user-photo {
            width: 100px;
            height: 100px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
<div class="dialog-shade"></div>
<header class="layout-header">
    <div class="container">
        <h1 class="title">编辑</h1>
        <a class="header-back" href="/user/updatePage"><i class="icon icon-left"></i></a>
        <ul class="tool-list">
            <li class="tool-item " ><span id="info-submit" onclick="updateData()">保存</span></li>
        </ul>
    </div>
</header>
<div class="layout-body">
    <div class="container">
        <section class="person-center-box">
            <div id="update-photo" class="update-photo">
                <input accept="image/*" type="file" id="photo" value="" />
            </div>
            <ul class="person-msg">
                <li class="person-photo">
                    <label>头像</label>
                    <div class="user-msg"><img class="user-photo" id="exist-photo" src="{$user['photo']}"></div>
                </li>
                <li>
                    <label>姓名</label>
                    <input id="name" class="user-msg" value="{$user['name']}" disabled/>
                </li>
                <li>
                    <label>性别</label>
                    <div class="user-sex-hide">

                        <label><input name="sex" value="0" type="radio" <if condition="$user['sex'] eq '0'">checked</if>> 男</label>
                        <label><input name="sex" value="1" type="radio" <if condition="$user['sex'] eq '1'">checked</if>> 女</label>
                    </div>
                </li>
                <li>
                    <label>电话</label>
                    <input class="user-msg" id="phone" value="{$user['phone']}">
                </li>
                <li>
                    <label>邮箱</label>
                    <div class="user-msg">
                        <a href="/user/emailChangePage" id="email" class="email">{$user['email']}</a> <i class="icon icon-right" ></i>
                    </div>
                </li>
                <li>
                    <label>密码</label>
                    <div class="user-msg"><a href="/user/changePswdPage" id="password" class="password">修改密码</a> <i class="icon icon-right" ></i></div>
                </li>
                <li>
                    <label>地区</label>
                    <input id="area" class="user-msg" value="{$user['area']}">
                </li>
            </ul>
            <ul class="person-msg person-msg2">
                <li>
                    <label>学校</label>
                    <input id="school" class="user-msg" value="{$user['school']}">
                </li>
                <li>
                    <label>专业</label>
                    <input id="professional" class="user-msg"  value="{$user['professional']}"/>
                </li>
                <li>
                    <label>学历</label>
                    <input id="education" class="user-msg"  value="{$user['education']}">
                </li>
                <li>
                    <label>自我描述</label>
                    <div>
                        <textarea rows="8" id="desc" class="user-msg user-desc">{$user['desc']}</textarea>
                    </div>
                </li>
            </ul>
        </section>
    </div>
</div>
<include file="Common/script" />
<script>
    $('.person-photo').on('click',function(){
        $('.dialog-shade').fadeIn(400);
        $('.update-photo').fadeIn(400);

    });
    $('#photo').change(function(event) {
        $('.dialog-shade').fadeOut(400);
        $('.update-photo').fadeOut(400);
        updateData();
        location.reload(true);
    });

    function updateData(){
            // e.preventDefault();
            var sex = $('input[name="sex"]:checked').val();
            var phone = $('#phone').val();
            if(!phone){
                eui.msg('电话不能为空 ！');
                return false;
            }
            var area = $('#area').val();
            if(!area){
                eui.msg('地区不能为空 ！');
                return false;
            }
            var school = $('#school').val();
            if(!school){
                eui.msg('学校不能为空 ！');
                return false;
            }
            var professional = $('#professional').val();
            if(!professional){
                eui.msg('专业不能为空 ！');
                return false;
            }
            var education = $('#education').val();
            if(!education){
                eui.msg('学历不能为空 ！');
                return false;
            }
            var desc = $('#desc').val();
            if(!desc){
                eui.msg('个人简介不能为空 ！');
                return false;
            }

            var formData = new FormData();
            formData.append('sex', sex);
            formData.append('phone', phone);
            formData.append('area', area);
            formData.append('school', school);
            formData.append('professional', professional);
            formData.append('education', education);
            formData.append('desc', desc);
            formData.append('file', $('#photo')[0].files[0]);

            $.ajax({
                url: '/user/update',
                data: formData,
                type: 'POST',
                dataType: 'json',
                processData: false,
                contentType: false,
                success: function (obj) {
                    if (obj.code === 0) {
                        eui.msg('修改成功');
                        window.location.href='/user/updatePage';
                    } else {
                        eui.msg('修改失败');
                    }

                },
                error: function () {
                    eui.alert('系统出错');
                }
            })
    };
</script>
</body>
</html>

